package org.apache.lucene.index;

import java.io.IOException;

import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;

public class TagBlockInfos implements TagWriteable {
  public long[] positions;
  public boolean[] tlogs;
  public int[] docFreqs;
  public int termNum;
  public boolean tlog;
  
  public TagBlockInfos() {}
  
  // TODO: record difs between numbers
  public TagBlockInfos(int termNum, boolean tlog, long position, IndexInput indexInput, long pointerBase) throws IOException {
    this.tlog = tlog;
    indexInput.seek(position);
    this.termNum = termNum;
    //termNum = indexInput.readVInt();
    int num = indexInput.readVInt();
    positions = new long[num];
    tlogs = new boolean[num];
    docFreqs = new int[num];
    for (int x=0; x < num; x++) {
      positions[x] = indexInput.readVLong() + pointerBase;
    }
    for (int x=0; x < num; x++) {
      tlogs[x] = TagUtil.toBoolean(indexInput.readByte());
    }
    for (int x=0; x < num; x++) {
      docFreqs[x] = indexInput.readVInt();
    }
  }
  
  public void write(IndexOutput output) throws IOException {
    //output.writeVInt(termNum);
    output.writeVInt(positions.length);
    for (long p : positions) {
      output.writeVLong(p);
    }
    for (boolean b : tlogs) {
      output.writeByte(TagUtil.toByte(b));
    }
    for (int df : docFreqs) {
      output.writeVInt(df);
    }
  }
  /**
  public static TagBlockInfo[] load(boolean tlog, TagBlockInfos tagBlockInfos, IndexInput indexInput) throws IOException {
    TagBlockInfo[] array = new TagBlockInfo[tagBlockInfos.positions.length];
    for (int x=0; x < tagBlockInfos.positions.length; x++) {
      indexInput.seek(tagBlockInfos.positions[x]);
      array[x] = new TagBlockInfo(tlog, indexInput);
    }
    return array;
  }
  **/
}
